package spring.angularjs.domain;

// Generated Oct 14, 2014 9:02:21 PM by Hibernate Tools 3.4.0.CR1

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

import spring.angularjs.customannotation.CardNumber;
import spring.angularjs.customannotation.FirstLastName;
import spring.angularjs.customannotation.LoginId;
import spring.angularjs.customannotation.MidName;
import spring.angularjs.customannotation.Phone1;
import spring.angularjs.customannotation.Phone2;
import spring.angularjs.customannotation.UniqueLoginId;

/**
 * Userinfo generated by hbm2java
 */
@Entity
@Table(name = "userinfo", catalog = "finalprojectangularjs")
public class Userinfo implements java.io.Serializable {

	@Size(min=5, message="Username at least 5 characters")
	@LoginId
	@UniqueLoginId
	private String loginId;
	private Status status;
	private Role role;
	
	@Size(min=8, message="Password at least 8 characters")
	private String password;
	
	@CardNumber
	private String cardnumberid;
	
	@FirstLastName
	private String firstname;
	@FirstLastName
	private String lastname;
	
	@MidName
	private String midname;
	
	@Phone1
	private String phone1;
	
	@Phone2
	private String phone2;
	
	@NotEmpty(message="Address not empty")
	private String address1;
	private String address2;
	
	@NotEmpty(message="Email not empty")
	@Email(message="Invalid Email")
	private String email1;
	
	@Email(message="Invalid Email")
	private String email2;
	private byte[] image;
	private Set<History> histories = new HashSet<History>(0);

	public Userinfo() {
	}

	public Userinfo(String loginId, Status status, Role role, String password,
			String cardnumberid, String firstname, String lastname,
			String phone1, String address1, String email1) {
		this.loginId = loginId;
		this.status = status;
		this.role = role;
		this.password = password;
		this.cardnumberid = cardnumberid;
		this.firstname = firstname;
		this.lastname = lastname;
		this.phone1 = phone1;
		this.address1 = address1;
		this.email1 = email1;
	}

	public Userinfo(String loginId, Status status, Role role, String password,
			String cardnumberid, String firstname, String lastname,
			String midname, String phone1, String phone2, String address1,
			String address2, String email1, String email2, byte[] image,
			Set<History> histories) {
		this.loginId = loginId;
		this.status = status;
		this.role = role;
		this.password = password;
		this.cardnumberid = cardnumberid;
		this.firstname = firstname;
		this.lastname = lastname;
		this.midname = midname;
		this.phone1 = phone1;
		this.phone2 = phone2;
		this.address1 = address1;
		this.address2 = address2;
		this.email1 = email1;
		this.email2 = email2;
		this.image = image;
		this.histories = histories;
	}

	public Userinfo(String loginId, Status status, Role role, String password,
			String cardnumberid, String firstname, String lastname,
			String midname, String phone1, String phone2, String address1,
			String address2, String email1, String email2, byte[] image) {
		super();
		this.loginId = loginId;
		this.status = status;
		this.role = role;
		this.password = password;
		this.cardnumberid = cardnumberid;
		this.firstname = firstname;
		this.lastname = lastname;
		this.midname = midname;
		this.phone1 = phone1;
		this.phone2 = phone2;
		this.address1 = address1;
		this.address2 = address2;
		this.email1 = email1;
		this.email2 = email2;
		this.image = image;
	}

	@Id
	@Column(name = "loginId", unique = true, nullable = false, length = 45)
	public String getLoginId() {
		return this.loginId;
	}

	public void setLoginId(String loginId) {
		this.loginId = loginId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "statusid", nullable = false)
	public Status getStatus() {
		return this.status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	// Not using lazy loading because when authiry using user.getRole().getRoleName()
	// using fetch.LAZY will error "No session"
	@ManyToOne
	@JoinColumn(name = "roleid", nullable = false)
	public Role getRole() {
		return this.role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@Column(name = "password", nullable = false, length = 500)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "cardnumberid", nullable = false, length = 45)
	public String getCardnumberid() {
		return this.cardnumberid;
	}

	public void setCardnumberid(String cardnumberid) {
		this.cardnumberid = cardnumberid;
	}

	@Column(name = "firstname", nullable = false, length = 45)
	public String getFirstname() {
		return this.firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	@Column(name = "lastname", nullable = false, length = 45)
	public String getLastname() {
		return this.lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	@Column(name = "midname", length = 45)
	public String getMidname() {
		return this.midname;
	}

	public void setMidname(String midname) {
		this.midname = midname;
	}

	@Column(name = "phone1", nullable = false, length = 11)
	public String getPhone1() {
		return this.phone1;
	}

	public void setPhone1(String phone1) {
		this.phone1 = phone1;
	}

	@Column(name = "phone2", length = 11)
	public String getPhone2() {
		return this.phone2;
	}

	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}

	@Column(name = "address1", nullable = false, length = 45)
	public String getAddress1() {
		return this.address1;
	}

	public void setAddress1(String address1) {
		this.address1 = address1;
	}

	@Column(name = "address2", length = 45)
	public String getAddress2() {
		return this.address2;
	}

	public void setAddress2(String address2) {
		this.address2 = address2;
	}

	@Column(name = "email1", nullable = false, length = 45)
	public String getEmail1() {
		return this.email1;
	}

	public void setEmail1(String email1) {
		this.email1 = email1;
	}

	@Column(name = "email2", length = 45)
	public String getEmail2() {
		return this.email2;
	}

	public void setEmail2(String email2) {
		this.email2 = email2;
	}

	@Column(name = "image")
	public byte[] getImage() {
		return this.image;
	}

	public void setImage(byte[] image) {
		this.image = image;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "userinfo")
	public Set<History> getHistories() {
		return this.histories;
	}

	public void setHistories(Set<History> histories) {
		this.histories = histories;
	}

}
